package com.maxus.mini.open.api.controller.topic;

import java.util.List;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.maux.mini.data.api.redis.RedisService;
import com.maux.mini.data.api.topic.TopicItemService;
import com.maux.mini.data.api.user.UserService;
import com.maxus.mini.common.Constants;
import com.maxus.mini.common.utils.BeanUtilsExtended;
import com.maxus.mini.common.vo.ResBody;
import com.maxus.mini.entity.topic.TopicItem;
import com.maxus.mini.entity.user.User;
import com.maxus.mini.entity.vo.topic.TopicItemVo;
import com.maxus.mini.open.api.controller.BaseController;
import com.maxus.mini.open.api.vo.req.P800005Vo;
import com.maxus.mini.open.api.vo.res.PR800005Vo;

/**
 * 收藏项controller
 * 
 * @author wujinsong
 *
 */
@RestController()
@RequestMapping(value = "api/v1.0/topicItem")
public class TopicItemController extends BaseController {
	@Reference(version = "1.0.0")
	private RedisService redisService;
	@Reference(version = "1.0.0")
	private UserService<User, User> userService;
	@Reference(version = "1.0.0")
	private TopicItemService<TopicItem, TopicItem> topicItemService;

	/**
	 * 获取话题列表
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "listMaxTopicItemList")
	@ResponseBody()
	public ResBody listMaxTopicItemList(P800005Vo req) {
		PR800005Vo retVo = new PR800005Vo();
		List<TopicItem> topics = null;

		String key = Constants.CKEY_TOPIC_LIST;
		if (redisService.getList(key, TopicItem.class) != null) {
			topics = redisService.getList(key, TopicItem.class);
		}

		if (topics != null) {
			retVo.setItemVos(topics);

			return retVo;
		}

		TopicItemVo vo = new TopicItemVo();
		try {
			BeanUtilsExtended.copyProperties(vo, req);
			topics = topicItemService.page(vo).getContent();
			redisService.setList(key, topics);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		retVo.setItemVos(topics);

		return retVo;
	}
}
